package com.cskaoyan.gateway.controller.user;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.user.IUserVerifyService;
import com.mall.user.annotation.Anoymous;
import com.mall.user.constants.SysRetCodeConstants;
import com.mall.user.dto.UserVerifyRequest;
import com.mall.user.dto.UserVerifyResponse;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
@Anoymous
public class UserVerifyController {

    @Reference(timeout = 3000,check = false)
    private IUserVerifyService userVerifyService;

    @RequestMapping("/verify")
    public ResponseData verify(@RequestParam String uuid, @RequestParam String username) {
        //验证
        if (StringUtils.isEmpty(uuid) || StringUtils.isEmpty(username)) {
            return new ResponseUtil<>().setErrorMsg("注册用户名/序号不能为空");
        }
        //修改数据库的userverify member
        UserVerifyRequest userVerifyRequest = new UserVerifyRequest();
        userVerifyRequest.setUserName(username);
        userVerifyRequest.setUuid(uuid);
        UserVerifyResponse userVerifyResponse = userVerifyService.verify(userVerifyRequest);

        if (userVerifyResponse.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())) {
            return new ResponseUtil<>().setData(null);
        }

        return new ResponseUtil<>().setErrorMsg(userVerifyResponse.getMsg());
    }
//        UserVerifyResponse response = userService.verify(request);
//        if (response.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())){
//            return new ResponseUtil<>().setErrorMsg(SysRetCodeConstants.USERVERIFY_INFOR_INVALID.getCode());
//        }
//        return new ResponseUtil<>().setData(null);
//    }

 }
